*09_raw_1920_figure.do

capture log close

global root =  "/disk/bulkw/nencka/schooling_pandemic/2021_10_18_final/"
global input   "$root/Input"
global scripts "$root/Scripts"
global output  "$root/Output"
global temp    "$root/Temp"
global log     "$root/Log"
global figures "$root/Figures"

set scheme plotplain



*****************************************************************************
*****************************************************************************
*****************************************************************************


log using "$log/09_raw_1910_1920_figure", replace text

*Load 1910 and 1920 census data

	
use "$temp/analysis_data_shortrun.dta", clear
	sum days_closed, d

	tab age_at_census census_year
	cap drop age_bin

	gen age_bin = 1 if inrange(age_at_census,0,5)
	replace age_bin = 2 if inrange(age_at_census,6,10)
	replace age_bin = 3 if inrange(age_at_census,11,14)
	replace age_bin = 4 if inrange(age_at_census,15,18)
	replace age_bin = 5 if inrange(age_at_census,19,21)
	replace age_bin = 6 if inrange(age_at_census,22,25)
	

	tab age_bin, mi 


sum days_closed, d
tab bdays_closed, m
tab days_closed bdays_closed, m

keep if inrange(bdays_closed,1,3)




*Construct raw school attendance measure by age bin and census year

 foreach yearval in 1910 1920 {

	preserve
		keep if census_year==`yearval'
		bys age_bin bdays_closed: egen mean = mean(in_school)
		keep age_bin bdays_closed mean
		duplicates drop
		list
		
		lab def bucket_ts  1 "0-5"  2 "6-10"  3 "11-14" 4 "15-18" 5 "19-21" 6 "22-25" 
		lab values age_bin bucket_ts

		separate mean, by(bdays_closed) shortlabel
		label variable mean1 "School closed 0-21 days"
		label variable mean2 "School closed 22-35 days"
		label variable mean3 "School closed 36+ days"

		sort bdays_closed age_bin 
		list
		save $temp/rawdataattend_`yearval', replace

		line `r(varlist)' age_bin, lcolor(gs8) xtitle(Age in `yearval') ysc(r(0 1)) ylab(0(0.2)1) ytitle(% Attending School) title("")  ///
			|| scatter `r(varlist)' age_bin, mstyle(p1) connect(l) ///
				legend(position(6) order(1 "School closed 0-21 days" 2 "School closed 22-35 days" 3 "School closed 36+ days")) ///
				xlabel(1 "0-5"  2 "6-10"  3 "11-14" 4 "15-18" 5 "19-21" 6 "22-25")

		graph export "$figures/rawschool`yearval'.eps", replace 
	restore

}

cd $figures
!mogrify -density 2000 -format png -- rawschool*.eps



log close

